import asyncio
import time


async def get_html(seconds):
    print('waiting for spider....')
    await asyncio.sleep(seconds)
    print('done!!')


if __name__ == '__main__':
    task1 = get_html(1)
    task2 = get_html(2)
    task3 = get_html(6)
    tasks = [task1, task2, task3]
    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(asyncio.wait(tasks))
    except KeyboardInterrupt as e:
        all_tasks = asyncio.Task.all_tasks()
        for t in all_tasks:
            print('task cancel!!')
            t.cancel()
        loop.stop()
        loop.run_forever()
    finally:
        loop.close()
        pass
